* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization
* The Effect of Distance on Timely Take-up in the Control and Signal at 5 Group
* **************************************************************************** *
/*
** Purpose:  Generates Figure :
			The Effect of Distance on Timely Take-up in the Control and Signal at 5 


*/
* **************************************************************************** *
* **************************************************************************** *


	* Set the format/style of bar graphs
	cd   "${Replicate_SocialSignals_Out}/colorschemes/"

	
	grstyle set color economist, reverse
	grstyle set plain
	grstyle set legend, klength(small) nobox
	set scheme s2color
	grstyle init myscheme,  replace
	grstyle set lpattern

	
	* ----------------------------------------------------------------------------

	use  "${Replicate_SocialSignals_dtaInter}/ListingFollowUp_analysis.dta", clear


	* Keep only children that were at least 12 months age the last time we observed them:
	keep if age_pikin >= 365

	* Drop babies born in December 2017 and January 2018:
	keep if dob < td(01dec2017)

	count


	* ----------------------------------------------------------------------------
  * Construct outcome and run regresion analysis:

	label var bcg      "Vaccine 1"
	label var penta1   "Vaccine 2"
	label var penta2   "Vaccine 3"
	label var penta3   "Vaccine 4"
	label var measles1 "Vaccine 5"

	label var treat3   "Signal at 4"
	label var treat4   "Signal at 5"
	label var treat2   "Uninformative Bracelet"

	summ      bcg penta1 penta2 penta3 measles1
	summ      treat*


	* ----------------------------------------------------------------------------
	* Code Vaccine outcomes:

		* Code Vaccine 1 outcome
		local a = 91

		foreach var in bcg {
			replace `var' = 0          if `var'==1 & age_`var'>=`a' & age_`var'!=.
			replace `var' = 0          if `var'==. & age_pikin>=`a' & age_pikin!=.
			replace `var' = .          if age_pikin<`a'
		}


		* Code Vaccine 2 outcome
		local b = 122

		foreach var in penta1 {
			replace `var' = 0          if `var'==1 & age_`var'>=`b' & age_`var'!=.
			replace `var' = 0          if `var'==. & age_pikin>=`b' & age_pikin!=.
			replace `var' = .          if age_pikin<`b'

			replace `var' = 0          if bcg ==0 & `var'==1
		}


		* Code Vaccine 3 outcome
		local c = 152

		foreach  var in penta2 {
			replace `var' = 0          if `var'==1 & age_`var'>=`c' & age_`var'!=.
			replace `var' = 0          if `var'==. & age_pikin>=`c' & age_pikin!=.
			replace `var' = .          if age_pikin<`c'

			replace `var' = 0          if penta1 ==0 & `var'==1
		}


		* Code Vaccine 4 outcome
		local d = 183

		foreach  var in penta3 {
			replace `var' = 0          if `var'==1 & age_`var'>=`d' & age_`var'!=.
			replace `var' = 0          if `var'==. & age_pikin>=`d' & age_pikin!=.
			replace `var' = .          if age_pikin<`d'

			replace `var' = 0          if penta2 ==0 & `var'==1
		}


		* Code Vaccine 5 outcome
		local e = 350

		foreach var in measles1 {
			replace `var' = 0 if `var'==1&age_`var'>=`e'&age_`var'!=.
			replace `var' = 0 if `var'==.&age_pikin>=`e'&age_pikin!=.
			replace `var' = . if age_pikin<`e'

			replace `var' = 0 if penta3 ==0&`var'==1
		}



		summ    bcg penta1 penta2 penta3 measles1

		summ    bcg penta1 penta2 penta3 measles1      if inlist(intervention_arm,1,4)

		tab     distance                               if inlist(intervention_arm,1,4)


		graph drop _all

		foreach distance of numlist 0(1)5 {
			summ  distance      if distance == `distance' & inlist(intervention_arm,1,4), detail
			local N_`distance' = trim("`: display %-9.0gc r(N)'")
		}

		* Plot figure for BCG / Vaccine 1
		binscatter ///
		bcg distance    ///
		if inlist(intervention_arm,1,4), by(intervention_arm)    ///
		ytitle("Share of Children Vaccinated")                   ///
		subtitle("Vaccine 1")                                    ///
		ylabel(0.4(0.1)1, angle(horizontal))                     ///
		yscale(range(0.4 1))                                     ///
		xtitle("") xlabel(0 1 2 3 4 5, nogrid)                           ///
		msymbol(s t s s) linetype(qfit)     ///
		legend(col(2) order(1 "Control" 2 "Signal 5"))           ///
		lcolors(midblue cranberry) mcolors(midblue cranberry) name(bcg) 


		* Plot figure for Penta 1 / Vaccine 2
		binscatter ///
		penta1 distance     ///
		if inlist(intervention_arm,1,4),  by(intervention_arm)   ///
		ytitle("Share of Children Vaccinated")                   ///
		subtitle("Vaccine 2")                                    ///
		ylabel(0.4(0.1)1, angle(horizontal))                     ///
		yscale(range(0.4 1))                                     ///
		xtitle("") xlabel(0 1 2 3 4 5, nogrid)                           ///
		msymbol(s t s s) linetype(qfit)                          ///
		legend(col(2) order(1 "Control" 2 "Signal 5"))           ///
		lcolors(midblue cranberry) mcolors(midblue cranberry)  name(penta1)



		* Plot figure for Penta 2 / Vaccine 3
		binscatter  ///
		penta2 distance  ///
		if inlist(intervention_arm,1,4),  by(intervention_arm)   ///
		ytitle("Share of Children Vaccinated")                       ///
		subtitle("Vaccine 3")                         ///
		ylabel(0.4(0.1)1, angle(horizontal))                     ///
		yscale(range(0.4 1))                                     ///
		xtitle("") xlabel(0 1 2 3 4 5, nogrid)                           ///
		msymbol(s t s s) linetype(qfit)                          ///
		legend(col(2) order(1 "Control" 2 "Signal 5"))           ///
		lcolors(midblue cranberry) mcolors(midblue cranberry) name(penta2)



		* Plot figure for Penta 3 / Vaccine 4
		binscatter  ///
		penta3 distance   ///
		if inlist(intervention_arm,1,4),    by(intervention_arm)     ///
		ytitle("Share of Children Vaccinated")                       ///
		subtitle("Vaccine 4")                                        ///
		ylabel(0.4(0.1)1, angle(horizontal))                         ///
		yscale(range(0.4 1))                                         ///
		xtitle("") xlabel(0 1 2 3 4 5, nogrid)                               ///
		msymbol(s t s s) linetype(qfit)                              ///
		legend(col(2) order(1 "Control" 2 "Signal 5"))               ///
		lcolors(midblue cranberry) mcolors(midblue cranberry) name(penta3)



		* Plot figure for Measles 1 / Vaccine 5
		binscatter  ///
		measles1 distance   ///
		if inlist(intervention_arm,1,4),  by(intervention_arm)         ///
		ytitle("Share of Children Vaccinated")                         ///
		subtitle("Vaccine 5")                                          ///
		ylabel(0.4(0.1)1, angle(horizontal))                           ///
		yscale(range(0.4 1))                                           ///
		xtitle("") xlabel(0 1 2 3 4 5, nogrid)                                 ///
		msymbol(s t s s) linetype(qfit)                                ///
		legend(col(2) order(1 "Control" 2 "Signal 5"))                 ///
		lcolors(midblue cranberry) mcolors(midblue cranberry) name(measles1)




		* Plot the combined figure with vaccines 2,3,4, and 5
		grc1leg ///
		penta1 penta2 penta3 measles1, legendfrom(penta1) cols(2) graphregion(color(white))
		graph export "${Replicate_SocialSignals_Figures}/Figure_TimelyVaccination_Distance_S5vsControl_NEW.jpg", replace




********************************************************************************
** End of the Dofile !!!
********************************************************************************
